<template>
  <div class="public-login">
    <mtHeader
      fixed
      style="background: none;height:1rem"
    >
        <div class="header-left iconfont" slot="left" @click="$router.back(-1)">&#xe623;</div>
        <!-- <router-link to="register">
            
        </router-link> -->
        <div slot="right">
            <router-link to="/public/register">
                <p class="header-r">注册</p>
            </router-link>
        </div>
        
    </mtHeader>
    <div class="container">
        <div class="cen">
            <p class="con-tit">登录</p>
            <input class="con-phone" placeholder="请输入手机号码" v-model="phone"/>
            
            <input placeholder="请输入密码" class="con-password" v-model="password"/>
            <div class="con-agreement">
                <router-link to="forgetPassword">
                    <div class="agreement-right">忘记密码</div>
                </router-link>
            </div>
            <!-- <button class="btnLogin" @click="btnLogin">登录</button> -->
            <mt-button type="default" size="large" @click="btnLogin" style="width: 100%;
              margin-top: 1.27rem;
              height: 0.9rem;
              line-height: 0.9rem;
              text-align: center;
              color: #fff;
              background: #FAB52F;
              font-size: 0.3rem;
              font-weight: 600;
              letter-spacing: 2px;"
            >登录</mt-button>
        </div>
        <div class="bot">
                <div class="bot-cn1"></div>
                <router-link to="/home1">
                    <p class="bot-cn2">随便看看</p>
                </router-link>
                <div class="bot-cn1"></div>
        </div>
    </div>
  </div>
</template>
<script>
import { Header,Button,Toast  } from "mint-ui";
import {phoneLogin,login} from '@/request/api';
export default {
  name: "login",
  components: {
    mtHeader: Header,
    mtButton:Button
  },
  data: function() {
    return {
      phone:null,
      sendCode:null,
      password:null,
      
    };
  },
  methods: {
   btnLogin(){
      let t = this
      let regphone=/^1(3|4|5|7|8)\d{9}$/
      let reg = new RegExp(/^[0-9a-zA-Z_]{6,12}$/)
      if(!regphone.test(this.phone)){
        Toast("请输入正确的手机号")
          return
      }
      if(!reg.test(this.password)){
        Toast("请输入6-12位密码")
          return
      }
      let password=this.$md5(this.password)
      login({"phone":this.phone,"password":password,'cfrom':this.cfrom,"version":this.version,"channel":this.channel}).then(function(res) {
        if(res.status!=="_0000"){
          Toast("登录失败")
          return
        }
        console.log(res)
        sessionStorage.setItem("userInfo",JSON.stringify(res.data))
        Toast("登录成功")
        setTimeout(() => {
          t.$router.go(-1)
        }, 1000);
	    })
      .catch(function (error) {
	       Toast(error);
      });
    }
  }
};
</script>
<style lang="less" scoped>
@import url('~styles/common.less');
</style>